home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1249 / invert2.t < prev    next >
Text File  |  1997-04-18  |  771b  |  45 lines

  1. %
  2. % "invert2" inverts a two by two matrix
  3. %
  4. %   Sample program for the T Interpreter by:
  5. %
  6. %   Stephen R. Schmitt
  7. %   962 Depot Road
  8. %   Boxborough, MA 01719
  9. %
  10.  
  11. const DIM : int := 2
  12.  
  13. program
  14.  
  15.     var x, y, z : rmatrix
  16.     var det : real
  17.     label program_exit :
  18.  
  19.     x[0,0] := 6.0                      % matrix to invert
  20.     x[0,1] := 3.0
  21.     x[1,0] := 2.0
  22.     x[1,1] := 4.0
  23.  
  24.     put "matrix X:"
  25.     print_mat( x )
  26.     det := invert( x, y, true )
  27.  
  28.     if det = 0.0 then
  29.  
  30.         put "is singular"
  31.         goto program_exit
  32.  
  33.     end if
  34.     
  35.     put "determinant of X = ", det
  36.     put "the inverse of X is:"
  37.     print_mat( y )
  38.  
  39.     put "check result:"
  40.     mul_mat_mat( x, y, z )
  41.     print_mat( z )
  42.  
  43.     program_exit:
  44.  
  45. end program